import logging

import requests


class EmpManageApi(object):
    # 添加员工
    def add_emp(self, req_head, req_data):
        resp = requests.post(url="http://ihrm2-test.itheima.net/api/sys/user/",
                             headers=req_head, json=req_data)
        return resp

    # 查询员工
    def query_emp(self, emp_id, req_head):
        resp = requests.get(url="http://ihrm2-test.itheima.net/api/sys/user/" + emp_id,
                            headers=req_head)
        return resp

    # 修改员工
    def modify_emp(self, emp_id, req_head, req_data):
        resp = requests.put(url="http://ihrm2-test.itheima.net/api/sys/user/" + emp_id,
                            headers=req_head, json=req_data)
        return resp

    # 删除员工
    def del_emp(self, emp_id, req_head):
        resp = requests.delete(url="http://ihrm2-test.itheima.net/api/sys/user/" + emp_id,
                               headers=req_head)


if __name__ == '__main__':
    emp = EmpManageApi()
    # 请求头
    req_head = {"Authorization": "0fada111-b7f0-4e6e-9e57-65c55ae387d8"}
    # 请求体
    req_data = {"username": "jack123", "mobile": "13858037122", "workNumber": "666"}
    emp_id = "1570684095179010048"
    resp = emp.add_emp(req_head, req_data)
    # print("添加员工：", resp.json())
    logging.info(resp.json())
    # resp = emp.query_emp(emp_id,req_head)
    # print("查询员工：",resp.json())
